/******************
人员类考核
* */
<template>
  <el-dialog
    :title="dialogTitle"
    :close-on-click-modal="false"
    :visible.sync="visible"
    width="80%"
    top="8vh"
    @close="closeDialog()"
  >
    <el-form ref="dataForm" :model="dataForm" label-position="right" label-width="120px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="周期名称" style="width:60%">
            <span>{{fatherData.period}}</span>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="考核时间" style="width:60%">
            <span>{{fatherData.assessBeginTime?fatherData.assessBeginTime.slice(0,10):""}}--{{fatherData.assessEndTime?fatherData.assessEndTime.slice(0,10):''}}</span>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="考核名称" style="width:60%">
            <span>{{dataForm.name}}</span>
          </el-form-item>
        </el-col>
        <!--news 2022/4/8 -->
        <el-col :span="12">
          <el-form-item label="模板名称:" prop="templateId" style="width:60%">
            <el-select
              v-model="dataForm.templateId"
              placeholder="请选择模板"
              class="xiaLa"
              style="width: 100%"
              :clearable="true"
              @change="selecteRefresh"
            >
              <el-option
                v-for="(item, index) in templateNamesList"
                :key="index"
                :label="item.name"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="被考核人" prop="ids" style="width:60%;">
            <el-button v-if="dialogTitle=='新增人员考核'" icon="el-icon-user-solid" type="text"></el-button>
            <span v-for="it in options" :key="it.userId">
              <el-tooltip
                class="item"
                :disabled="options.length < 3"
                effect="dark"
                :content="shaiXuan(options, '被考核人')"
                placement="top-start"
              >
                <span style="font-size: 16px; color: #303745">{{ it.userName }}、</span>
              </el-tooltip>
            </span>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div style="height: 10px; border-top: 1px solid #b0bde2"></div>
    <div class="tabBox">
      <div class="btnBox"></div>
    </div>
    <el-row>
      <el-table
        style="width: 100%;margin-top:20px"
        :data="dataList"
        border
        stripe
        header-align="center"
      >
        <el-table-column prop="type" align="center" label="指标类别"></el-table-column>
        <el-table-column prop="name" align="center" label="指标名称" show-overflow-tooltip></el-table-column>
        <el-table-column prop="weight" align="center" label="权重(%)"></el-table-column>
        <el-table-column prop="formula" align="center" label="计算公式"></el-table-column>
        <el-table-column prop="targetValue" align="center" label="目标值"></el-table-column>
        <el-table-column prop="unit" align="center" label="单位" show-overflow-tooltip>
          <template slot-scope="scope">
            <span>{{scope.row.unit}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="completeValue" align="center" label="完成值获取方式"></el-table-column>
        <el-table-column
          prop="provideRealName"
          align="center"
          label="数据提供部门/人"
          show-overflow-tooltip
          width="200"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.isLiaison==0">{{scope.row.provideRealName}}</span>
            <span v-else>{{scope.row.provideDeptName}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="normRule" align="center" label="指标规则" show-overflow-tooltip></el-table-column>
<!--        <el-table-column type="index" align="center" width="80" label="排序号" show-overflow-tooltip></el-table-column>-->
      </el-table>
    </el-row>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" plain @click="closeDialog()">返回</el-button>
    </span>
  </el-dialog>
</template>

<script>
import {
  addExamin,
  editExamin,
  getMbnameSelect
} from "@/api/dailyExamine/targetExamine/createAssessment";
import {
  targetAllFill,
  indexExaminAllDataList //查询指标
} from "@/api/dailyExamine/targetExamine/indicatorFormulation";

export default {
  data() {
    return {
      isEdit: true,
      isDept: false,
      fatherData: {}, //新增时总部启动的考核数据
      dataList: [], //指标数组
      options: [], //被考核人的数组
      dialogTitle: "新增人员考核", //弹窗标题
      visible: false, //最外层弹窗显隐
      dataForm: {
        //数据表单
        ids: []
      },
      //news 2022/4/8
      templateNamesList: []
    };
  },
  watch: {},
  methods: {
    //news 2022/4/8 获取模板列表
    getTemplateName() {
      getMbnameSelect().then(r => {
        r.data.data.forEach(ele => {
          let item = {
            name: ele.templateName,
            value: ele.id
          };
          this.templateNamesList.push(item);
          if (ele.isZmb == 1) {
            this.dataForm.templateId = ele.id;
          }
        });
      });
    },
    selecteRefresh() {
      this.$forceUpdate();
    },
    //筛选出姓名与职务
    shaiXuan(data, type) {
      var list = [],
        obj = {};
      if (type == "被考核人") {
        for (var i in data) {
          list.push(data[i].userName);
        }
      }
      return list.toString();
    },

    // 初始化
    init(data, editData, type) {
      this.visible = true;
      this.fatherData = data.data;
      if (type == "edit") {
        this.isEdit = true;
      } else {
        this.isEdit = false;
      }
      this.getTemplateName(); //模板
      if (editData) {
        if (editData) {
          this.dialogTitle = "查看";
          this.dataForm = editData;
          this.options.push({
            deptId: editData.assessDeptId,
            deptName: editData.assessDeptName,
            userName: editData.assessRealName,
            userId: editData.assessUserId,
            userCode: editData.assessUserName
          });
          indexExaminAllDataList(editData.id)
            .then(r => {
              if (r.data.code == 0) {
                this.dataList = r.data.data;
                this.personSelectChange();
              }
            })
            .catch(err => {});
        }
      }
    },
    // 关闭
    closeDialog() {
      this.visible = false;
      this.$emit("closeDialog");
    }
  }
};
</script>

<style lang="scss">
.tabBox {
  width: 100%;
  .btnBox {
    display: flex;
    justify-content: space-between;
  }
}
</style>
